package pers.course.week7;

import java.util.Scanner;

public class ArrayMove{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        String[] strs = new String[num];
        char[][] numArray = new char[num][];
        char[][] moveNumArray = new char[num][];
        for (int i = 0; i < num; i++) {
            strs[i] = in.next();
            numArray[i] = strs[i].toCharArray();
        }
        int bits = in.nextInt();
        for (int i = 0; i < num; i++) {
            int size = numArray[i].length;
            moveNumArray[i] = new char[size];
            for (int j = 0; j < size; j++) {
                moveNumArray[i][(j + bits) % size] = numArray[i][j];
            }
            if (moveNumArray[i][0] == '0') {
                for (int j = 1; j < size; j++) {
                    System.out.print(moveNumArray[i][j]);
                }
            } else {
                for (int j = 0; j < size; j++) {
                    System.out.print(moveNumArray[i][j]);
                }
            }
            System.out.println();
        }
    }
}
